package GUI_CONTROLER;
 

import java.io.*;
import java.util.Vector;

import javax.swing.JOptionPane;

import start.ClientConsole;

import GUI.*;
import client.*;
import client.ChatIF;
import common.*;
import GUI.*;


public class LoginUserC{

	public String name;
	public String Pass;
	public Integer UserType;
	ClientConsole chat;
	
	public LoginUserC(ClientConsole chat) 
	{
		this.chat = chat;
	}
	public int HandleLoginRequestFromGui(String user,String Pass)
	{
		this.name = user;
		this.Pass = Pass;
		int i;
		String LoginQuery = new String("select UserName,Password,UserType from users where UserName="+user);
		chat.client.flag=0; // Reset msg receive flag to null
		chat.SendMsg(LoginQuery); // Send Query

		while(0 == chat.client.flag)
		{
		}
		//chat.client.MsgFromServer;
		if (chat.client.MsgFromServer instanceof Vector)
		{
			String Suser=new String();
			String Spass=new String();
			Vector<String[]> result=(Vector<String[]>)chat.client.MsgFromServer;
			String[] array= result.get(1);
			Suser = array[0];
			Spass = array[1];
			UserType = UserType.parseInt(array[2]);
			System.out.println("user:"+array[0]+" pass: "+array[1]+" type: "+array[2]);
			System.out.println("\nUser exists");
			
			if( !(Spass.equalsIgnoreCase(Pass)) ) // Case user does not exist
			{
				return 99;
			}
		}
		else
		{
			// implement no entry exists.
			return 100;
		}
	return UserType;
	}
	
}
